package org.springframework.aop.framework.autoproxy;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator;
import org.springframework.context.support.GenericApplicationContext;

/**
 * @author: mornd
 * @dateTime: 2023/5/17 - 15:24
 * AbstractAutoProxyCreator
 */
public class Demo2 {
    public static void main(String[] args) {
        GenericApplicationContext context = new GenericApplicationContext();
        context.registerBean(AnnotationAwareAspectJAutoProxyCreator.class);
        context.registerBean(MyAspect.class);
        context.refresh();

        AnnotationAwareAspectJAutoProxyCreator bean = context.getBean(AnnotationAwareAspectJAutoProxyCreator.class);
        Object o = bean.wrapIfNecessary(new Target1(), "aspect1", "aspect1");
        System.out.println(o.getClass());
    }

    static class Target1 {
        public void foo() {
            System.out.println("foo...");
        }
    }

    @Aspect
    static class MyAspect {
        @Before("execution(* foo())")
        public void before() {
            System.out.println("before...");
        }
    }
}
